﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Document_Management
{
    public partial class frmXiuliRen : Form
    {
        static string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["庫存管理"].ConnectionString;
        TextBox tb;
        public frmXiuliRen(TextBox tb)
        {
            InitializeComponent();
            this.tb = tb;
        }

        private void btnSearch修理人_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(connectionString);
            try
            {
                con.Open();
                string strcmd = "sp_修理人_查詢";
                SqlDataAdapter cmd = new SqlDataAdapter(strcmd, con);
                cmd.SelectCommand.CommandType = CommandType.StoredProcedure;
                //if (txt廠區.Text != "") cmd.SelectCommand.Parameters.AddWithValue("@廠區代號", txt廠區.Text);
                if (dtgSearch修理人.Text != "") cmd.SelectCommand.Parameters.AddWithValue("@修理人代號與姓名", txtSearch修理人.Text);
                DataTable dt = new DataTable();
                cmd.Fill(dt);
                dtgSearch修理人.DataSource = dt;
                con.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                con.Close();
            }
        }

        private void frmXiuliRen_Load(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(connectionString);
            try
            {
                con.Open();
                string strcmd = "sp_修理人_查詢";
                //string strcmd = " Select * From 圖面廠區";
                SqlDataAdapter cmd = new SqlDataAdapter(strcmd, con);
                cmd.SelectCommand.CommandType = CommandType.StoredProcedure;
                //cmd.SelectCommand.Parameters.AddWithValue("@廠區名稱","f");
                DataTable dt = new DataTable();
                cmd.Fill(dt);
                dtgSearch修理人.DataSource = dt;
                PublicClass.setRowNumber(dtgSearch修理人);
                con.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                con.Close();
            }
        }

        private void btnSearchTypeOK_Click(object sender, EventArgs e)
        {
            try
            {
                int r = dtgSearch修理人.CurrentCell.RowIndex;
                string sup修理人Id = dtgSearch修理人.Rows[r].Cells[0].Value.ToString();
                tb.Text = sup修理人Id;
                this.Close();
            }
            catch
            {

            }
        }

        private void dtgSearch修理人_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            PublicClass.setRowNumber(dtgSearch修理人);
        }
    }
}
